import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Date;

public class ScoreSprite extends Sprite {

	protected Image scoreBar;

	protected Gameloop gameloop;

	protected Font font = new Font("Berlin Sans FB Demi", Font.BOLD, 38);

	protected String beeHitScore;
	protected String ladyHitScore;
	protected String totalGameScore;
	protected String stopwatch;

	protected int xBee;
	protected int xLady;
	protected int xScore;
	protected int xstopwatch;
	protected int yBarScore;

	protected int beeScore;
	protected int ladyScore;
	protected int totalScore;

	protected long elapsedMilliseconds;
	protected long elapsedHours;
	protected long elapsedMinutes;
	protected long elapsedSeconds;

	protected String elapsedTime;

	public int getTotalScore() {
		return totalScore;
	}

	public String getTotalGameScore() {
		return totalGameScore;
	}
	public String getStopwatch() {
		return stopwatch;
	}

	public ScoreSprite(Gameloop gl) {
		super();

		gameloop = gl;

		scoreBar = ImageLoader.get().read("/Images/ScoreBar.png");

		width = gameloop.getWidth();
		height = 82;

		x = 0;
		y = 0;

		xBee = 75;
		xLady = 240;
		xstopwatch = 520;
		xScore = 880;
		yBarScore = 30;

	}

	private String stopwatch() {

		elapsedMilliseconds = new Date().getTime()
				- gameloop.startTime.getTime();
		elapsedHours = elapsedMilliseconds / 3600000;
		elapsedMinutes = (elapsedMilliseconds = elapsedMilliseconds
				- (elapsedHours * 3600000)) / 60000;
		elapsedSeconds = (elapsedMilliseconds = elapsedMilliseconds
				- (elapsedMinutes * 60000)) / 1000;

		return String.format("%02d", elapsedHours) + ":"
				+ String.format("%02d", elapsedMinutes) + ":"
				+ String.format("%02d", elapsedSeconds);
	}

	public void update() {

		totalScore += gameloop.getTarget().getTotalScore();
		totalGameScore = Integer.toString(totalScore);

		beeScore += gameloop.getTarget().getBeeScore();
		beeHitScore = Integer.toString(beeScore);

		ladyScore += gameloop.getTarget().getLadyScore();
		ladyHitScore = Integer.toString(ladyScore);

		stopwatch = this.stopwatch();

	}

	public void draw(Graphics g) {
		g.drawImage(scoreBar, x, y, width, height, null);

		g.setFont(font);

		g.drawString(beeHitScore, xBee, yBarScore);
		g.drawString(ladyHitScore, xLady, yBarScore);
		g.drawString(totalGameScore, xScore, yBarScore);
		g.drawString(stopwatch, xstopwatch, yBarScore);

	}
}
